<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	数据选择页
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$tabs=array(
	array('op'=>'main','title'=>'基础页面'),
	array('op'=>'coupon','title'=>'优惠券列表'),
	array('op'=>'goods','title'=>'产品列表'),
	array('op'=>'package','title'=>'产品套餐'),
	array('op'=>'news','title'=>'新闻列表'),
);
if($_RQ['op']=='main'){
	//选择小程序内置页
	$list=get_wxapp_pages();
	$return['list']=$list;
	$return['htmls']=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edid'=>false,'del_one'=>false,'delall'=>false,'pagelist'=>false,'list'=>array(
			array('type'=>'string','name'=>'title','title'=>'页面'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'page','title'=>'选取'),
		)),
	);
	exi($return);
}
if($_RQ['op']=='coupon'){
	//优惠券详情
	$pindex=max(1,intval($_RQ['page']));
	$psize=10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$total=0;
	$fields=array('id','title','createtime');
	$list=pdo_getslice('core_card',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('y/m/d H:i:s',$item['createtime']);
			$item['url']='pages/goods/detail?id='.$item['id'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='goods'){
	//产品详情
	$pindex=max(1,intval($_RQ['page']));
	$psize=10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$total=0;
	$fields=array('id','title','createtime');
	$list=pdo_getslice('core_account_product',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('y/m/d H:i:s',$item['createtime']);
			$item['url']='pages/goods/detail?id='.$item['id'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='package'){
	//产品套餐详情
}

if($_RQ['op']=='news'){
	//新闻详情
	$pindex=max(1,intval($_RQ['page']));
	$psize=10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$total=0;
	$fields=array('id','title','createtime');
	$list=pdo_getslice('core_account_article',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('y/m/d H:i:s',$item['createtime']);
			$item['url']='pages/news/item?id='.$item['id'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}